import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Mainn {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int cont=scanner.nextInt();
        int aa[][]=new  int[cont][2];
        for (int i = 0; i < cont; i++) {
            aa[i][0]=scanner.nextInt();
            aa[i][1]=scanner.nextInt();
        }
        sjhuju sjhuju=new sjhuju();
        sjhuju.chuli(aa);
    }
}

class sjhuju{
    public int chuli(int[][] a){
        Arrays.sort(a, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1]-o2[1];
            }
        });

        for (int i = 0; i < a.length; i++) {
            for (int i1 = 0; i1 < 2; i1++) {
                System.out.print(a[i][i1]);
            }
            System.out.println();
        }

        return 0;
    }
}